package com.rfid.service;

import org.apache.log4j.Logger;

import com.entitymapper.EntityMapperException;
import com.entitymapper.EntityStatusException;
import com.rfid.entityMapper.ProductFieldMapperToWrite;
import com.rfid.service.exception.ClientException;
import com.rfid.service.util.MapperUtils;

public class RFIDWriteInfoService {

	private static final Logger log = Logger.getLogger(RFIDWriteInfoService.class);
	private MapperUtils utils;
	
	public RFIDWriteInfoService() {
		utils = MapperUtils.getInstance();
	}
	
	public void writeInfo(Object obj) {
		try {
			utils.getMapper().writeFromObject(obj, new ProductFieldMapperToWrite());
		}catch(EntityMapperException ex) {
			if(ex instanceof EntityStatusException) {
				log.error("write Object have Exception for: " + ex.getMessage());
			}else {
				log.error("write " + obj + " has an error :" + ex.getMessage());
				throw new ClientException(ex);
			}
		}
	}
}
